package com.flute.icrawler.app.task.entity;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.flute.icrawler.app.task.ITaskState;

public class WaitingTaskState implements ITaskState {

	private static Logger logger = LoggerFactory
			.getLogger(WaitingTaskState.class);

	@Override
	public ITaskState handle(CrawlTask crawlTask) {

		logger.info("I'm waiting crawlTask name=" + crawlTask.getName());

		if (0 != crawlTask.getIntervalDay()
				&& crawlTask.getFinishTime() != 0
				&& System.currentTimeMillis() < crawlTask.getFinishTime()
						+ crawlTask.getIntervalDay()) {

			// 周期任务已完成 但运行周期点未到

		} else {

			// 提交成功
			if (crawlTask.submitCrawlerJob()) {
				return CrawlTask.STATE_RUNNING;
			} else {
				return CrawlTask.STATE_WAITING;
			}

		}

		return null;
	}

}
